using System.Configuration;
using System.Linq;

namespace mock_ehr_lib.Data.LookupServices
{
    public class RxNormLookupService : ILookupService
    {
        private static RxNormLookupService _instance;
        private RxNormLookupService()
        {
            

        }
        public static RxNormLookupService Instance
        {
            get { return _instance ?? (_instance = new RxNormLookupService()); }
        }

        public string GetDescriptionByCode(string code)
        {
            var client = new DBManagerService();
            var conceptGroups = client.getAllRelatedInfo(code);
            if (conceptGroups.Any())
            {
                var groupWithConcepts = conceptGroups.Where(i => i.rxConcept.Any()).FirstOrDefault();
                if(groupWithConcepts != null)
                {
                    var concept = groupWithConcepts.rxConcept.FirstOrDefault();
                    return concept.STR;
                }
            }
            return null;
        }
    }
}